package com.lsy.weizhi2.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lsy.weizhi2.R;
import com.lsy.weizhi2.config.Constants;
import com.lsy.weizhi2.config.CostomFlag;
import com.zhy.autolayout.utils.AutoUtils;

/**
 * Created by 嗨哟 on 2017/3/14.
 */
public class HomeGridAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater layoutInflater;

    public HomeGridAdapter(Context context) {
        this.context = context;
        layoutInflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return CostomFlag.list_select.size()+1;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        GridHolder gridHolder=null;
        if(view==null){
            view=layoutInflater.inflate(R.layout.classify_gv_item,viewGroup,false);
            gridHolder=new GridHolder();
            gridHolder.classify_iv= (ImageView) view.findViewById(R.id.classify_iv);
            gridHolder.classify_tv= (TextView) view.findViewById(R.id.classify_tv);
            AutoUtils.autoSize(view);
            view.setTag(gridHolder);
        }else{
            gridHolder= (GridHolder) view.getTag();
        }
        if(i==CostomFlag.list_select.size()){
            gridHolder.classify_iv.setImageResource(R.mipmap.index_9);
            gridHolder.classify_tv.setText("全部微职");
        }else{
            gridHolder.classify_iv.setImageResource(CostomFlag.list_select.get(i).getImage());
            gridHolder.classify_tv.setText(CostomFlag.list_select.get(i).getName());

        }

        return view;
    }

    class GridHolder{
        ImageView classify_iv;
        TextView classify_tv;
    }
}
